//
//  DHSpecialEditionCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/4/12.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHSpecialEditionCell.h"
#import "DHNewsDetailController.h"
#import "YSLoopBanner.h"

@implementation DHSpecialEditionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.editionButton.layer.cornerRadius = self.editionButton.height / 2;
    
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];
}

- (void)updateCellWithArray:(NSArray *)arr{
    
    YSLoopBanner *loop = [[YSLoopBanner alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenWidth/1.275) scrollDuration:3.f];
    [self.scrollView addSubview:loop];
    
    if (arr.count > 0) {
        self.img_defaultImgView.hidden = YES;
        NSMutableArray *imgs = [NSMutableArray array];
        for (NSDictionary *model in arr) {
            [imgs addObject:[model objectForKey:@"specialPic"]];
        }
        
        loop.imageURLStrings = imgs;
        loop.clickAction = ^(NSInteger index) {
            NSLog(@"curIndex: %ld", index);
            NSDictionary *model = [arr objectAtIndex:index];
            DHNewsDetailController *vc = [[DHNewsDetailController alloc] initWithArticleID:[model objectForKey:@"_id"]];
            vc.hidesBottomBarWhenPushed = YES;
            [self.viewController.navigationController pushViewController:vc animated:YES];
            
        };
    }else{
        self.img_defaultImgView.hidden = NO;
    }
    
//    self.scrollView.contentSize = CGSizeMake(arr.count * kScreenWidth, self.scrollView.height);
//    
//    //TODO::
//    if (arr.count > 0) {
//        self.img_defaultImgView.hidden = YES;
//    }else{
//        self.img_defaultImgView.hidden = NO;
//    }
//    for (int i = 0; i < arr.count; i++) {
//        NSDictionary *model = [arr objectAtIndex:i];
//        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreenWidth, 0, kScreenWidth, kScreenWidth/1.275)];
//        [imageView dh_setImageURLString:[model objectForKey:@"specialPic"]];
//        imageView.userInteractionEnabled = YES;
//        imageView.contentMode = UIViewContentModeScaleAspectFill;
//        [imageView bk_whenTapped:^{
//            DHNewsDetailController *vc = [[DHNewsDetailController alloc] initWithArticleID:[model objectForKey:@"_id"]];
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.viewController.navigationController pushViewController:vc animated:YES];
//        }];
//        [self.scrollView addSubview:imageView];
//    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
